﻿/// <reference path="../typings/underscore/underscore.d.ts" />
/// <reference path="../typings/backbone/backbone.d.ts" />

import bb = Backbone;
import som = require("SalesOrderModels");
import cms = som.CustomerModels;

export module CustomerViews {
    export class CustomersSelectView extends bb.View<cms.CustomerShort>
    {
        private elm: JQuery;

        render(): bb.View<cms.CustomerShort> {
            this.$el.append("<select>");
            this.elm = $("select");

            this.collection.each(c => {
                var cv = new CustomerOptionView();
                cv.model = c;
                this.elm.append(cv.render().el);
            }, null);
            return this;
        }
    }

    export class CustomerOptionView extends bb.View<cms.CustomerShort>
    {
        render(): bb.View<cms.CustomerShort> {
            var templateProcessor = _.template($("#dropdowntemplate").html());
            var html = templateProcessor(this.model.toJSON());
            this.setElement(html);
            return this;
        }
    }
} 